//
//  ModuleDetailVC.m
//  Project
//
//  Created by 冯东辉 on 2018/9/21.
//  Copyright © 2018年 FengDongHui. All rights reserved.
//

#import "ModuleDetailVC.h"
#import "ModuleDetailCell.h"
#import "ZhiBiaoDetailVC.h"
#import <WXApi.h>
#import "LieHuaDetailVC.h"
#import "CityDetailVC.h"

@interface ModuleDetailVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSDictionary *dic_data;

@property (nonatomic, strong) NSArray *table_data;

@property (nonatomic, strong) UITableView *listTableV;

@property (nonatomic, assign) CGFloat maxNum;

/**
 * 头部
 */
@property (nonatomic, strong) UILabel *inD_DATA_l;
// 劣化指标
@property (nonatomic, strong) UIImageView *lieH_view;
// 平级 上升 下降
@property (nonatomic, strong) UIImageView *status_view;
// 维度
@property (nonatomic, strong) UILabel *status_l;
// 时间
@property (nonatomic, strong) UILabel *time_l;
// 最优
@property (nonatomic, strong) UILabel *youCityL;
// 最差
@property (nonatomic, strong) UILabel *chaCityL;

@property (nonatomic, strong) UILabel *noteL;

@property (nonatomic, strong) UIView *baseShareV;

@end

@implementation ModuleDetailVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setNavView];
    
    [self setHeadView];
    
    [self getDetailData];
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    self.navigationController.navigationBar.alpha = 0;
    [self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
}

#pragma mark - 自定义导航栏
- (void)setNavView {
    
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, GET_SCREEN_WIDTH(), SafeAreaTopHeight)];
    navView.backgroundColor = Base_color;
    [self.view addSubview:navView];
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, 44, 44)];
    [backBtn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(leftNavigationBarButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    
    UILabel *navTitleL = [[UILabel alloc] initWithFrame:CGRectMake(backBtn.right+10, SafeAreaTopHeight-44, GET_SCREEN_WIDTH()-44*2-20, 44)];
    navTitleL.text = _moduleName;
    navTitleL.textColor = UICOLOR_HEX(0xffffffff);
    navTitleL.textAlignment = NSTextAlignmentCenter;
    navTitleL.font = [UIFont systemFontOfSize:16];
    [navView addSubview:navTitleL];
    
    [self setFontSizeThatFits:navTitleL];
   
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(GET_SCREEN_WIDTH()-44, backBtn.top, 44, 44)];
    [rightBtn setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:rightBtn];
}

#pragma mark - 头部详情视图
- (void)setHeadView {

    UIView *headBaseV = [[UIView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, GET_SCREEN_WIDTH(), 145)];
    headBaseV.backgroundColor = Base_color;
    [self.view addSubview:headBaseV];
    
    _inD_DATA_l = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, GET_SCREEN_WIDTH(), 30)];
    _inD_DATA_l.text = @"1588.00";
    _inD_DATA_l.textColor = UICOLOR_HEX(0xffffffff);
    _inD_DATA_l.font = [UIFont boldSystemFontOfSize:35];
    _inD_DATA_l.textAlignment = NSTextAlignmentCenter;
    [headBaseV addSubview:_inD_DATA_l] ;
    
    _status_l = [[UILabel alloc] initWithFrame:CGRectMake(_inD_DATA_l.right+10, _inD_DATA_l.bottom-13, _status_l.width, 18)];
    _status_l.font = [UIFont boldSystemFontOfSize:15];
    [headBaseV addSubview:_status_l];
    
    _status_view = [[UIImageView alloc] initWithFrame:CGRectMake(_status_l.right+5, _status_l.top, 18, 18)];
    _status_view.contentMode = UIViewContentModeCenter;
    [headBaseV addSubview:_status_view];
    
    _time_l = [[UILabel alloc] initWithFrame:CGRectMake((GET_SCREEN_WIDTH()-116)/2.0f, _inD_DATA_l.bottom+20, 120, 20)];
    _time_l.textColor = UICOLOR_HEX(0xffffffff);
    _time_l.font = [UIFont systemFontOfSize:15];
    [headBaseV addSubview:_time_l];
    
    _lieH_view = [[UIImageView alloc] initWithFrame:CGRectMake(_time_l.left-51-10, _time_l.top, 51, _time_l.height)];
    _lieH_view.image = [UIImage imageNamed:@"module_lhzb"];
    _lieH_view.contentMode = UIViewContentModeCenter;
    _lieH_view.hidden = YES;
    [headBaseV addSubview:_lieH_view];
    
    UIButton *detailBtn = [[UIButton alloc] initWithFrame:CGRectMake(_time_l.right+10, _time_l.top+2, 50, 16)];
    [detailBtn setTitle:@"详情" forState:UIControlStateNormal];
    [detailBtn setTitleColor:UICOLOR_HEX(0xffffffff) forState:UIControlStateNormal];
    detailBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [detailBtn setBackgroundColor:UICOLOR_HEX(0xff0072c4)];
    detailBtn.layer.cornerRadius = 1;
    detailBtn.layer.masksToBounds = YES;
    [detailBtn addTarget:self action:@selector(pushDetail) forControlEvents:UIControlEventTouchUpInside];
    [headBaseV addSubview:detailBtn];
    
    UIView *middleV = [[UIView alloc] initWithFrame:CGRectMake(15, _time_l.bottom+10, GET_SCREEN_WIDTH()-30, 67)];
    middleV.backgroundColor = UICOLOR_HEX(0xffffffff);
    [headBaseV addSubview:middleV];
    
    UIView *slineV = [[UIView alloc] initWithFrame:CGRectMake((middleV.width-1)/2.0f, middleV.height/3.0f, 1, middleV.height/3.0f)];
    slineV.backgroundColor = UICOLOR_HEX(0xffd6d6d6);
    [middleV addSubview:slineV];
    
    UIButton *youBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, middleV.width/2.0f, middleV.height)];
    [youBtn addTarget:self action:@selector(pushCityDetail:) forControlEvents:UIControlEventTouchUpInside];
    youBtn.tag = 1000;
    [middleV addSubview:youBtn];
    
    UIButton *chaBtn = [[UIButton alloc] initWithFrame:CGRectMake(youBtn.right, 0, middleV.width/2.0f, middleV.height)];
    [chaBtn addTarget:self action:@selector(pushCityDetail:) forControlEvents:UIControlEventTouchUpInside];
    chaBtn.tag = 2000;
    [middleV addSubview:chaBtn];
    
    UIImageView *youImageV = [[UIImageView alloc] initWithFrame:CGRectMake(((middleV.width-1)/2.0f-62-5-16)/2.0f, 10, 16, 17)];
    youImageV.image = [UIImage imageNamed:@"module_you"];
    [youBtn addSubview:youImageV];
    
    UILabel *youL = [[UILabel alloc] initWithFrame:CGRectMake(youImageV.right+5, youImageV.top, 62, 17)];
    youL.text = @"全省最优";
    youL.textColor = UICOLOR_HEX(0xff000000);
    youL.font = [UIFont systemFontOfSize:15 weight:1];
    [youBtn addSubview:youL];
    
    UIImageView *chaImageV = [[UIImageView alloc] initWithFrame:CGRectMake(((middleV.width-1)/2.0f-62-5-16)/2.0f, 10, 16, 17)];
    chaImageV.image = [UIImage imageNamed:@"module_cha"];
    [chaBtn addSubview:chaImageV];
    
    UILabel *chaL = [[UILabel alloc] initWithFrame:CGRectMake(youImageV.right+5, youImageV.top, 62, 17)];
    chaL.text = @"全省最差";
    chaL.textColor = UICOLOR_HEX(0xff000000);
    chaL.font = [UIFont systemFontOfSize:15 weight:1];
    [chaBtn addSubview:chaL];
    
    _youCityL = [[UILabel alloc] initWithFrame:CGRectMake(0, youL.bottom+10, (middleV.width-1)/2.0f, 30)];
    _youCityL.textAlignment = NSTextAlignmentCenter;
    _youCityL.textColor = UICOLOR_HEX(0xff000000);
    _youCityL.font = [UIFont systemFontOfSize:16];
    [youBtn addSubview:_youCityL];
    
    _chaCityL = [[UILabel alloc] initWithFrame:CGRectMake(0, youL.bottom+10, (middleV.width-1)/2.0f, 30)];
    _chaCityL.textAlignment = NSTextAlignmentCenter;
    _chaCityL.textColor = UICOLOR_HEX(0xff000000);
    _chaCityL.font = [UIFont systemFontOfSize:16];
    [chaBtn addSubview:_chaCityL];
    
    UIButton *noteBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, headBaseV.bottom+30, middleV.width, 50)];
    [noteBtn setBackgroundColor:UICOLOR_HEX(0xffc7e4f9)];
    [noteBtn addTarget:self action:@selector(pushNextVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:noteBtn];
    
    _noteL = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, noteBtn.width-9-5-12, noteBtn.height)];
    _noteL.textColor = UICOLOR_HEX(0xff666666);
    _noteL.textAlignment = NSTextAlignmentLeft;
    _noteL.font = [UIFont systemFontOfSize:15];
    _noteL.numberOfLines = 0;
    [noteBtn addSubview:_noteL];
    
    UIImageView *noteImageV = [[UIImageView alloc] initWithFrame:CGRectMake(noteBtn.width-9-12, (noteBtn.height-17)/2.0f, 9, 17)];
    noteImageV.image = [UIImage imageNamed:@"more"];
    [noteBtn addSubview:noteImageV];
    
    _listTableV = [[UITableView alloc] initWithFrame:CGRectMake(noteBtn.left, noteBtn.bottom+10, noteBtn.width, GET_SCREEN_HEIGHT()-noteBtn.bottom-10)];
    _listTableV.backgroundColor = UICOLOR_HEX(0xffffffff);
    _listTableV.delegate = self;
    _listTableV.dataSource = self;
    _listTableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    _listTableV.estimatedRowHeight = 0;
    _listTableV.estimatedSectionHeaderHeight = 0;
    _listTableV.estimatedSectionFooterHeight = 0;
    [self.view addSubview:_listTableV];
    
    UIView *tableHeadV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _listTableV.width, 50)];
    tableHeadV.backgroundColor = UICOLOR_HEX(0xffffffff);
    _listTableV.tableHeaderView = tableHeadV;
    
    UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(5, tableHeadV.height-1, tableHeadV.width-10, 1)];
    hLine.backgroundColor = UICOLOR_HEX(0xffd6d6d6);
    [tableHeadV addSubview:hLine];
    
    UIImageView *pImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, tableHeadV.height)];
    pImageV.image = [UIImage imageNamed:@"module_note_p"];
    pImageV.contentMode = UIViewContentModeCenter;
    [tableHeadV addSubview:pImageV];
    
    UILabel *pNoteL = [[UILabel alloc] initWithFrame:CGRectMake(pImageV.right, 0, tableHeadV.width-pImageV.right, tableHeadV.height)];
    pNoteL.text = @"全省排名情况";
    pNoteL.textColor = UICOLOR_HEX(0xff000000);
    pNoteL.font = [UIFont systemFontOfSize:18 weight:1];
    [tableHeadV addSubview:pNoteL];
}

#pragma mark -更新数据
- (void)reloadSubViews {
    
    NSString *inD_DATA = [NSString stringWithFormat:@"%@", _dic_data[@"inD_DATA"]];
    if ([ProjectTools isValiString:inD_DATA]) {
        inD_DATA = @"0.00";
    }
    _inD_DATA_l.text = [NSString stringWithFormat:@"%.2f", [inD_DATA floatValue]];
    CGRect indRect = [ProjectTools getStringRectWithString:_inD_DATA_l.text font:_inD_DATA_l.font maxSize:CGSizeMake(999, _inD_DATA_l.height)];
    _inD_DATA_l.frame = CGRectMake((GET_SCREEN_WIDTH()-indRect.size.width)/2.0f-20, _inD_DATA_l.top, indRect.size.width, _inD_DATA_l.height);
    
    // 状态 1上升 2下降 0持平
    NSString *status_text = [NSString stringWithFormat:@"%@", _dic_data[@"lasttime_data"]];
    
    if ([ProjectTools isValiString:status_text]) {
        status_text = @"0.00";
    }
    
    _status_l.text = status_text;
    
    CGRect statusRect = [ProjectTools getStringRectWithString:_status_l.text font:_status_l.font maxSize:CGSizeMake(999, _status_l.height)];
    
    _status_l.frame = CGRectMake(_inD_DATA_l.right+5, _status_l.top, statusRect.size.width, 18);
    
    _status_view.frame = CGRectMake(_status_l.right+2, _status_l.top, 18, 18);
    
    NSInteger sort_id = [_dic_data[@"sorT_ID"] integerValue];
    
    if (sort_id == 0) {
        
        if ([status_text floatValue] == 0) {
            
            _status_view.image = [UIImage imageNamed:@"module_pingji"];
            _status_l.textColor = UICOLOR_HEX(0xffffffff);
            
        }else if ([status_text floatValue] > 0) {
            
            _status_view.image = [UIImage imageNamed:@"module_shangsheng"];
            _status_l.textColor = UICOLOR_HEX(0xff29fd31);
            
        }else {
            
            _status_view.image = [UIImage imageNamed:@"module_xiajiang"];
            _status_l.textColor = UICOLOR_HEX(0xfff95154);
        }
        
    }else {
        
        if ([status_text floatValue] == 0) {
            
            _status_view.image = [UIImage imageNamed:@"module_pingji"];
            _status_l.textColor = UICOLOR_HEX(0xffffffff);
            
        }else if ([status_text floatValue] > 0) {
            
            _status_view.image = [UIImage imageNamed:@"module_xiajiang"];
            _status_l.textColor = UICOLOR_HEX(0xfff95154);
            
        }else {
            
            _status_view.image = [UIImage imageNamed:@"module_shangsheng"];
            _status_l.textColor = UICOLOR_HEX(0xff29fd31);
        }
    }
    
    _time_l.text = [NSString stringWithFormat:@"%@", _dic_data[@"time"]];
    
    // 劣化指标 1劣化 0没劣化
    NSInteger iS_Degradation = [_dic_data[@"iS_Degradation"] integerValue];
    if (iS_Degradation == 0) {
        _lieH_view.hidden = YES;
    }else {
        _lieH_view.hidden = NO;
    }
    
    NSString *youStr = [NSString stringWithFormat:@"%@%@", _dic_data[@"maX_CityName"], _dic_data[@"maX_Data"]];
    [self setAttributedStr:youStr target:_youCityL color:Base_color location:[_dic_data[@"maX_CityName"] length] lenght:[_dic_data[@"maX_Data"] length]];
    
    NSString *chaStr = [NSString stringWithFormat:@"%@%@", _dic_data[@"miN_CityName"], _dic_data[@"miN_Data"]];
    [self setAttributedStr:chaStr target:_chaCityL color:UICOLOR_HEX(0xfff36c6e) location:[_dic_data[@"miN_CityName"] length] lenght:[_dic_data[@"miN_Data"] length]];
    
    _noteL.text = [NSString stringWithFormat:@"%@", _dic_data[@"reamke"]];
    
    [_listTableV reloadData];
}

#pragma mark - 获取详情数据
- (void)getDetailData {
    
    [[ProjectApi instance] getModuleDetailDataWithSid:_s_id callBack:^(NetModel *object) {
        
        if (object.isSuccessed) {
            
            self.dic_data = [NSDictionary dictionaryWithDictionary:object.service];
            
            self.table_data = [NSArray arrayWithArray:self.dic_data[@"list"]];
            
            CGFloat max = [self.dic_data[@"maX_Data"] floatValue];
            CGFloat min = [self.dic_data[@"miN_Data"] floatValue];
            
            if (max > min) {
                self.maxNum = max;
            }else {
                self.maxNum = min;
            }
            
            [self reloadSubViews];
            
        }else {
            
            [SVProgressHUD showErrorWithStatus:@"网络连接失败"];
            [SVProgressHUD dismissWithDelay:1.5f];
        }
    }];
}

#pragma mark - 分享
- (void)share {
    
    if (_baseShareV) {
        
        _baseShareV.hidden = NO;
        
        return;
    }

    _baseShareV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, GET_SCREEN_WIDTH(), GET_SCREEN_HEIGHT())];
    _baseShareV.backgroundColor = [UICOLOR_HEX(0xff000000) colorWithAlphaComponent:0.5f];
    [self.view.window addSubview:_baseShareV];
    
    UIButton *hyBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, GET_SCREEN_HEIGHT()-50-130, GET_SCREEN_WIDTH()/2.0f, 130)];
    hyBtn.backgroundColor = UICOLOR_HEX(0xffffffff);
    [hyBtn setImage:[UIImage imageNamed:@"share_wxhy"] forState:UIControlStateNormal];
    hyBtn.tag = 1000;
    [hyBtn addTarget:self action:@selector(wxShare:) forControlEvents:UIControlEventTouchUpInside];
    [_baseShareV addSubview:hyBtn];
    
    UIButton *pyqBtn = [[UIButton alloc] initWithFrame:CGRectMake(hyBtn.right, hyBtn.top, hyBtn.width, hyBtn.height)];
    pyqBtn.backgroundColor = UICOLOR_HEX(0xffffffff);
    [pyqBtn setImage:[UIImage imageNamed:@"share_pyq"] forState:UIControlStateNormal];
    pyqBtn.tag = 2000;
    [pyqBtn addTarget:self action:@selector(wxShare:) forControlEvents:UIControlEventTouchUpInside];
    [_baseShareV addSubview:pyqBtn];
    
    UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, hyBtn.bottom, GET_SCREEN_WIDTH(), 50)];
    cancelBtn.backgroundColor = UICOLOR_HEX(0xffEDEEEF);
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:UICOLOR_HEX(0xff000000) forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [cancelBtn addTarget:self action:@selector(hiddenShareView) forControlEvents:UIControlEventTouchUpInside];
    [_baseShareV addSubview:cancelBtn];
}

- (void)hiddenShareView {
    
    _baseShareV.hidden = YES;
}

- (void)wxShare:(UIButton *)btn {
    
    [self hiddenShareView];
    
    WXMediaMessage *message = [WXMediaMessage message];
    // 设置消息缩略图的方法
    // [message setThumbImage:[UIImage imageNamed:@"图片.png"]];
    
    // 多媒体消息中包含的图片数据对象
    WXImageObject *imageObject = [WXImageObject object];
    // 图片真实数据内容
    NSData *data = UIImagePNGRepresentation([self captureImageFromView]);
    imageObject.imageData = data;
    // 多媒体数据对象，可以为WXImageObject，WXMusicObject，WXVideoObject，WXWebpageObject等。
    message.mediaObject = imageObject;
    
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    if (btn.tag == 1000) {
        req.scene = WXSceneSession;
    }else {
        req.scene = WXSceneTimeline;
    }
    
    [WXApi sendReq:req];
}

-(UIImage *)captureImageFromView {
    
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size,NO, 0);
    
    [[UIColor clearColor] setFill];
    
    [[UIBezierPath bezierPathWithRect:self.view.bounds] fill];
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    [self.view.layer renderInContext:ctx];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
}
#pragma mark - 详情
- (void)pushDetail {
    
    ZhiBiaoDetailVC *vc = [[ZhiBiaoDetailVC alloc] init];
    vc.moduleName = _moduleName;
    vc.cityName = _cityName;
    vc.s_id = _dic_data[@"s_id"];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -
- (void)pushNextVC {
    
    LieHuaDetailVC *vc = [[LieHuaDetailVC alloc] init];
    vc.moduleName = _moduleName;
    vc.cityName = _cityName;
    vc.s_id = _dic_data[@"s_id"];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -
- (void)pushCityDetail:(UIButton *)btn {
    
    NSString *cityName_select = @"";
    
    if (btn.tag == 1000) {
        // 最优
        cityName_select = _dic_data[@"maX_CityName"];
        
    }else {
        // 最差
        cityName_select = _dic_data[@"miN_CityName"];
    }
    
    CityDetailVC *vc = [[CityDetailVC alloc] init];
    vc.moduleName = _moduleName;
    vc.cityName = cityName_select;
    vc.s_id = _dic_data[@"s_id"];
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark - tableView delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSDictionary *dic = _table_data[indexPath.row];
    NSString *cityName_select = dic[@"citY_NAME"];
    
    CityDetailVC *vc = [[CityDetailVC alloc] init];
    vc.moduleName = _moduleName;
    vc.cityName = cityName_select;
    vc.s_id = _dic_data[@"s_id"];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - tableView dataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [_table_data count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifierA = @"module_detail_cell";
    
    ModuleDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierA];
    
    if (cell == nil) {
        
        cell = [[ModuleDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierA];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor clearColor];
        cell.contentView.backgroundColor = [UIColor clearColor];
    }
    
    [cell reloadSubViewWithData:_table_data indexPath:indexPath maxNum:_maxNum];
    
    return cell;
}

/**
 设置富文本

 @param newString 文本内容
 @param label target
 @param color 颜色
 @param location 位置
 @param lenght 长度
 */
- (void)setAttributedStr:(NSString *)newString target:(UILabel *)label color:(UIColor *)color location:(NSInteger)location lenght:(NSInteger)lenght {
    
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:newString];
    
    [attributedStr addAttribute:NSKernAttributeName
     
                          value:@5
     
                          range:NSMakeRange(location-1, 1)];
    
    [attributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont boldSystemFontOfSize:18]
     
                          range:NSMakeRange(location, lenght)];
    
    [attributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:color
     
                          range:NSMakeRange(location, lenght)];
    
    label.attributedText = attributedStr;
}

@end
